import type { PermissionAttributes } from '@/utils/types/system';

import { CwindMenus } from '@/models/cwind_menus.model';
import { CwindRole } from '@/models/cwind_role.model';
/*
 * @Description: CwindPermission Entity
 * @Version: 2.0
 * @Author: cwind
 * @Date: 2022-10-28 17:23:20
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2025-05-12 17:35:31
 */
import {
  BelongsTo,
  Column,
  DataType,
  ForeignKey,
  IsUUID,
  Model,
  PrimaryKey,
  Table,
} from 'sequelize-typescript';

@Table({ tableName: 'cwind_permission' })
export class CwindPermission
  extends Model<PermissionAttributes, PermissionAttributes>
  implements PermissionAttributes
{
  // 菜单id
  @IsUUID(4)
  @ForeignKey(() => CwindMenus)
  @Column({ type: DataType.UUID, comment: '菜单id' })
  menu_id: string;

  @BelongsTo(() => CwindMenus)
  menuInfo: CwindMenus;

  @IsUUID(4)
  @PrimaryKey
  @Column({
    type: DataType.UUID,
    allowNull: false,
    defaultValue: DataType.UUIDV4,
    comment: '权限id',
  })
  permission_id: string;

  // 角色id
  @IsUUID(4)
  @ForeignKey(() => CwindRole)
  @Column({ type: DataType.UUID, comment: '角色id' })
  role_id: string;

  @BelongsTo(() => CwindRole)
  roleInfo: CwindRole;
}
